<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>来个好玩的</button>
    <button>下去吧</button>
    <hr>

    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class Video extends React.Component{

            state = {
                url: 'http://api.xiaohigh.com/video/random'
            }

            //渲染
            render(){
                console.log('渲染中....');
                return <div>
                    <button onClick={this.force}>强制更新</button><br/>
                    <video controls height="500" src={this.state.url} onClick={() => {
                            this.setState({
                                url: 'http://api.xiaohigh.com/video/random?t='+Date.now()
                            })
                        }}></video>
                </div>
            }

            //声明强制更新的回调
            force = () => {
                //另类的一招
                this.state.url = 'http://api.xiaohigh.com/video/random?t='+Date.now();
                //
                this.forceUpdate();
            }

            //组件应该要更新了
            shouldComponentUpdate(){
                console.log('组件应该要更新了...');
                //需要返回布尔类型的值, 决定后续回调的执行
                return true;
            }

            //组件将要更新
            componentWillUpdate(){
                console.log('组件将要更新...');
            }

            //组件完成了更新
            componentDidUpdate(){
                console.log('组件完成了更新...');
            }

            
        }

        //获取两个按钮
        let btns = document.querySelectorAll('button');

        //第一个按钮单击事件
        btns[0].onclick = function(){
            //挂载 渲染组件
            ReactDOM.render(<Video test="测试" />, document.querySelector("#root"));
        }

        //第二个按钮单击事件
        btns[1].onclick = function(){
            //卸载组件  unmount 卸载  component 组件  at 在   node 节点
            ReactDOM.unmountComponentAtNode(document.querySelector("#root"));
        }
    </script>
</body>
</html>